home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
System Booster
/
System Booster.iso
/
Systemmonitors
/
RSys
/
RSysSrc.lha
/
RSysFindFile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-19
|
19KB
|
745 lines
/*
***************************************************************************
*
* Datei:
* RSysFindFile.c
*
* Inhalt:
*
* --- Globale Routinen ---
*
* void FindFile ( void );
* void HandleFindFileKeys ( ULONG code );
* void MakeDevEntry ( struct List *list , char *str );
*
* --- Lokale Routinen ---
*
* static BOOL ClickedGadget ( void );
* static int OpenFindFileWindow ( void );
* static void *MyDevAllocRem ( long size );
* static void *MyFileAllocRem ( long size );
* static void HandleFindFileGadgets ( APTR object , ULONG code );
* static void MakeDevList ( void );
* static void MakeFileEntry ( char *str );
* static void refreshdevlists ( void );
* static void SaveFoundFiles ( void );
* static void SearchFile ( char *name );
*
* Bemerkungen:
* Disk-Format-Untersützung und Dateisuchroutinen.
*
* Erstellungsdatum:
* 07-Jul-93 Rolf Böhme
*
* Änderungen:
* 07-Jul-93 Rolf Böhme Erstellung
*
***************************************************************************
*/
#include "RSys.h"
static struct Window *FindFileWnd = NULL;
static struct Gadget *FindFileGList = NULL;
static UWORD FindFileZoom[4];
static struct Gadget *FindFileGadgets[10];
static UWORD FindFileLeft = 153;
static UWORD FindFileTop = 27;
static UWORD FindFileWidth = 330;
static UWORD FindFileHeight = 200;
static UBYTE *FindFileWdt = (UBYTE *) NAME " " VERSION " - Find File";
static UBYTE *CaseCYGad0Labels[]=
{
(UBYTE *) "No case sense",
(UBYTE *) "Case sense",
NULL
};
static UBYTE *DirFileCYGad0Labels[] = {
(UBYTE *)"Dirs + Files",
(UBYTE *)"Files",
(UBYTE *)"Directories",
NULL };
static struct List DevList;
static struct List SelDevList,
FoundList;
struct Remember *DevKey = NULL;
static struct Remember *FileKey = NULL;
static char pat[PATTERNLEN],
parsepat[PARSEPATLEN];
static int match_case = NO_CASE,
match_type = DF;
static UWORD FindFileGTypes[] = {
LISTVIEW_KIND,
LISTVIEW_KIND,
STRING_KIND,
BUTTON_KIND,
LISTVIEW_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
CYCLE_KIND,
CYCLE_KIND
};
static struct NewGadget FindFileNGad[] = {
4, 17, 157, 60, (UBYTE *)"Devices", NULL, GD_DeviceLV, PLACETEXT_ABOVE, NULL, NULL,
168, 17, 157, 60, (UBYTE *)"Selected Devices", NULL, GD_SelDevLV, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, NULL,
74, 113, 87, 13, (UBYTE *)"Pattern", NULL, GD_PatternGad, PLACETEXT_LEFT, NULL, NULL,
4, 97, 157, 13, (UBYTE *)"Start/Stop Search", NULL, GD_StartStopGad, PLACETEXT_IN, NULL, NULL,
4, 144, 321, 52, (UBYTE *)"Found files/dirs", NULL, GD_FoundLV, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, NULL,
168, 97, 157, 13, (UBYTE *)"Save found list", NULL, GD_SaveFoundListGad, PLACETEXT_IN, NULL, NULL,
168, 81, 77, 13, (UBYTE *)"Sel all", NULL, GD_AllGad, PLACETEXT_IN, NULL, NULL,
248, 81, 77, 13, (UBYTE *)"Sel none", NULL, GD_NoneGad, PLACETEXT_IN, NULL, NULL,
4, 81, 157, 13, NULL, NULL, GD_CaseCYGad, 0, NULL, NULL,
168, 113, 157, 13, NULL, NULL, GD_DirFileCYGad, 0, NULL, NULL
};
static ULONG *FindFileGTags[] = {
(ULONG *)(GTLV_Labels), (ULONG *)&DevList, (ULONG *)(TAG_DONE),
(ULONG *)(GTLV_Labels), (ULONG *)&SelDevList, (ULONG *)(TAG_DONE),
(ULONG *)(GTST_MaxChars), (ULONG *)256, (ULONG *)(TAG_DONE),
(ULONG *)(GA_Disabled), (ULONG *)TRUE, (ULONG *)(TAG_DONE),
(ULONG *)(GTLV_Labels), (ULONG *)&FoundList, (ULONG *)(GTLV_ReadOnly), (ULONG *)TRUE, (ULONG *)(TAG_DONE),
(ULONG *)(TAG_DONE),
(ULONG *)(TAG_DONE),
(ULONG *)(TAG_DONE),
(ULONG * )(GTCY_Labels), (ULONG *)&CaseCYGad0Labels[ 0 ], (ULONG *)(TAG_DONE),
(ULONG * )(GTCY_Labels), (ULONG *)&DirFileCYGad0Labels[ 0 ], (ULONG *)(TAG_DONE)
};
static int gl[] = {GD_DeviceLV - GD_DeviceLV,
GD_SelDevLV - GD_DeviceLV,
GD_PatternGad - GD_DeviceLV,
GD_FoundLV - GD_DeviceLV};
/*
* OpenFindFileWindow() öffnet ein Window mit Gadgets, mit
* denen die Auswahl- und Suchkriterien eingegeben werden
* können
*/
static int
OpenFindFileWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = FindFileLeft, wtop = FindFileTop, ww, wh;
DPOS;
AdjustWindowDimensions(Scr, FindFileLeft, FindFileTop, FindFileWidth, FindFileHeight,
&wleft, &wtop, &ww, &wh);
if ( ! ( g = CreateContext( &FindFileGList ))) return 1L;
for( lc = 0, tc = 0; lc < FindFile_CNT; lc++ )
{
CopyMem((char * )&FindFileNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
FindFileGadgets[ lc ] = g = CreateGadgetA((ULONG)FindFileGTypes[ lc ], g, &ng, ( struct TagItem * )&FindFileGTags[ tc ] );
makelabelvisible(FindFileGadgets[lc]);
while( FindFileGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g ) return 2L;
}
FindFileZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)FindFileWdt, strlen((char *)FindFileWdt )) + 80;
FindFileZoom[0] = FindFileZoom[1] = 0;
FindFileZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
if ( ! ( FindFileWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww,
WA_Height, wh,
WA_IDCMP, IDCMP_VANILLAKEY|
LISTVIEWIDCMP|
STRINGIDCMP|
BUTTONIDCMP|
CYCLEIDCMP|
IDCMP_CLOSEWINDOW|
IDCMP_CHANGEWINDOW|
IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR|
WFLG_DEPTHGADGET|
WFLG_CLOSEGADGET|
WFLG_RMBTRAP|
WFLG_ACTIVATE |
WFLG_SMART_REFRESH,
WA_Title, FindFileWdt,
WA_Zoom, FindFileZoom,
WA_PubScreenFallBack,TRUE,
WA_PubScreen, Scr,
TAG_DONE )))
return 4L;
FindFileZoom[0] = FindFileWnd->LeftEdge;
FindFileZoom[1] = FindFileWnd->TopEdge;
FindFileZoom[2] = FindFileWnd->Width;
FindFileZoom[3] = FindFileWnd->Height;
RefreshRastPort(FindFileWnd,FindFileGadgets,gl, 4, FALSE, FindFileGList);
return NULL;
}
/*
* MyDevAllocRem() reserviert Speicher aus einer Remember-Liste
* für die Verzeichnis-Einträge
*/
static void *
MyDevAllocRem(long size)
{
void *ptr = (void *)AllocRemember(DEVKEY, size, MEMF_CLEAR | MEMF_ANY);
if (NOT(ptr))
{
ErrorHandle("Device list", MEMORY_ERR, ALLOC_FAIL, NO_KILL);
Flags.quit_ff = 1;
}
return (ptr);
}
/*
* MyFileAllocRem() reserviert Speicher aus einer Remember-Liste
* für die Datei-Einträge
*/
static void *
MyFileAllocRem(long size)
{
void *ptr = (void *)AllocRemember(FILEKEY, size, MEMF_CLEAR | MEMF_ANY);
if (NOT(ptr))
{
ErrorHandle("File list", MEMORY_ERR, ALLOC_FAIL, NO_KILL);
Flags.quit_ff = 1;
}
return (ptr);
}
/*
* refreshdevlists() erneuert die Anzeige der ListViews mit den
* Inhalten der Listen der selektierten und der nicht selektierten
* Devices
*/
static void
refreshdevlists(void)
{
InitListView(FindFileWnd,FindFileGadgets[GD_DeviceLV - GD_DeviceLV], &DevList,UNSETLVPOS);
InitListView(FindFileWnd,FindFileGadgets[GD_SelDevLV - GD_DeviceLV], &SelDevList,UNSETLVPOS);
return;
}
/*
* MakeDevEntry() erzeugt einen neuen Listeneintrag in die
* Liste der Devices
*/
void
MakeDevEntry(struct List *list, char *str)
{
struct Node *node = MyDevAllocRem(sizeof(struct Node));
if (NOT(node)) return;
node->ln_Pri = 0;
node->ln_Type = NT_USER;
node->ln_Name = MyDevAllocRem(strlen(str) + 1);
if (NOT(node->ln_Name)) return;
strcpy(node->ln_Name, str);
AddNodeSorted(list, node, 0);
return;
}
/*
* MakeFileEntry() erzeugt einen Listeneintrag in die Liste der
* gefundenen Dateien. Der Eintrag wird dann in die bestehende
* Liste alphabetisch einsortiert
*/
static void
MakeFileEntry(char *str)
{
struct Node *node = MyFileAllocRem(sizeof(struct Node));
if (NOT(node)) return;
node->ln_Pri = 0;
node->ln_Type = NT_USER;
node->ln_Name = MyDevAllocRem(strlen(str) + 1);
if (NOT(node->ln_Name)) return;
strcpy(node->ln_Name, str);
AddNodeSorted(&FoundList, node, 0);
InitListView(FindFileWnd,FindFileGadgets[GD_FoundLV - GD_DeviceLV], &FoundList,UNSETLVPOS);
return;
}
/*
* MakeDevList() erzeugt eine Liste aus angemeldeten Devices
* (Volumes) und Assigns. Die Devices werden der Reihe nach
* ausgelesen und in die Liste einsortiert. Assigns werden mit
* einem führenden "-" versehen, damit sie in der Liste
* unterschieden werden können
*/
static void
MakeDevList(void)
{
char dev[80], str[100];
struct DosList *dl;
dl = LockDosList(LDF_VOLUMES | LDF_READ);
while (dl = NextDosEntry(dl, LDF_VOLUMES | LDF_READ))
{
sprintf(str, " %s:", B2CStr(dev, dl->dol_Name));
MakeDevEntry(&DevList, str);
}
UnLockDosList(LDF_VOLUMES | LDF_READ);
dl = LockDosList(LDF_ASSIGNS | LDF_READ);
while (dl = NextDosEntry(dl, LDF_ASSIGNS | LDF_READ))
{
sprintf(str, "\-%s:", B2CStr(dev, dl->dol_Name));
MakeDevEntry(&DevList, str);
}
UnLockDosList(LDF_ASSIGNS | LDF_READ);
return;
}
static int breakit = FALSE;
/*
* ClickedGadget() prüft, ob das Start/Stop-Gadget betätigt
* wurde. Mit einem AutoRequester wird nachgefragt, ob die
* Suche nach Dateien eingestellt werden soll
*/
static BOOL
ClickedGadget(void)
{
register struct IntuiMessage *mess;
ULONG class;
APTR adr;
BOOL ret = FALSE;
while ((mess = (struct IntuiMessage *) GT_GetIMsg(FindFileWnd->UserPort)) != NULL)
{
class = mess->Class;
adr = mess->IAddress;
GT_ReplyIMsg(mess);
switch (class)
{
case IDCMP_CHANGEWINDOW:
case IDCMP_REFRESHWINDOW:
RefreshRastPort(FindFileWnd,FindFileGadgets,gl, 4, TRUE, NULL);
MakeWindowRefresh(FindFileWnd);
break;
case IDCMP_GADGETUP:
if ((adr == (APTR) FindFileGadgets[GD_StartStopGad - GD_DeviceLV]) &&
Question(FindFileWnd, "Do you want to cancel searching?", YES))
{
ret = TRUE;
breakit = TRUE;
}
break;
}
}
return ret;
}
/*
* SearchFile() wird rekursiv mit dem dem Namen eines
* Verzeichnisses oder Devices aufgerufen. Es durchsucht dann
* alle Verzeichnisse nach vorgegebenem Suchmuster. Die
* gefundenen Einträge werden in die entsprechenden Listen
* eingetragen
*/
static void
SearchFile(char *name)
{
struct ExAllControl *eac;
struct ExAllData *EAData,
*ead;
int more;
BPTR lock;
UBYTE newdir[MAXFULLNAME],
foundname[MAXFULLNAME];
BOOL(*matchfunc[2]) (UBYTE *, UBYTE *) =
{
MatchPatternNoCase, MatchPattern
};
if (ClickedGadget()|| breakit || Flags.quit_ff) return;
if (NOT(lock = Lock((UBYTE *) name, ACCESS_READ))) return;
if (eac = AllocDosObject(DOS_EXALLCONTROL, NULL))
{
eac->eac_LastKey = 0;
EAData = MyAllocVec((MAXLARGEMEM+1) * sizeof(struct ExAllData),
MEMF_ANY | MEMF_CLEAR, NO_KILL);
if (EAData)
{
do
{
more = ExAll(lock, EAData, MAXLARGEMEM * sizeof(struct ExAllData),
ED_SIZE, eac);
if ((!more) && (IoErr()!= ERROR_NO_MORE_ENTRIES))
{
ErrorHandle(name, DOS_EXALL_ERR, EXALL_FAIL, NO_KILL);
break;
}
if (eac->eac_Entries == 0)
continue;
ead = EAData;
do
{
if ((*matchfunc[match_case]) ((UBYTE *) parsepat,
FilePart((UBYTE *) ead->ed_Name)))
{
strncpy((char *)foundname, name, MAXFULLNAME);
if (AddPart(foundname, ead->ed_Name, MAXFULLNAME))
{
if (ead->ed_Type > 0) strcat((char *)foundname, " (dir)");
if((match_type == DF) || ((match_type == FI) && (ead->ed_Type <= 0)) ||
((match_type == DI) && (ead->ed_Type > 0)))
MakeFileEntry((char *)foundname);
}
}
if (ead->ed_Type > 0)
{
strncpy((char *)newdir, name, MAXFULLNAME);
if (AddPart(newdir, ead->ed_Name, MAXFULLNAME)) SearchFile((char *)newdir);
}
ead = ead->ed_Next;
} while (ead && NOT(ClickedGadget())&& NOT(breakit) && NOT(Flags.quit_ff));
} while (more);
MyFreeVec(EAData);
}
FreeDosObject(DOS_EXALLCONTROL, eac);
}
else ErrorHandle("ExAll()-Control", MEMORY_ERR, ALLOC_FAIL, NO_KILL);
UnLock(lock);
return;
}
/*
* SaveFoundFiles() speichert die Liste mit den gefunden
* Dateien und Verzeichnissen in einer Datei ab
*/
static void
SaveFoundFiles(void)
{
char head[PARSEPATLEN];
if (GetFile(FindFileWnd,"RAM:","RSys-FoundFiles.DAT","#?.DAT",
"Select File for saving list","Save"))
{
sprintf(head, "Found files (Pattern: %s)", pat);
SaveList(FindFileWnd, (char *)_fullpath, head, &FoundList, FALSE);
}
return;
}
static void
HandleFindFileGadgets(APTR object, ULONG code)
{
struct Node *clicknode,
*node,
*remnode;
int ID, i;
LONG (*parse_func[2]) (UBYTE *, UBYTE *, long)=
{
ParsePatternNoCase, ParsePattern
};
DPOS;
ID = ((struct Gadget *) object)->GadgetID;
HandleHelp((enum RSysNumbers)ID);
switch (ID)
{
case GD_DeviceLV:
clicknode = GetNode(&DevList, code);
Remove(clicknode);
AddTail(&SelDevList, clicknode);
refreshdevlists();
if (strlen(pat)) EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], TRUE);
break;
case GD_SelDevLV:
clicknode = GetNode(&SelDevList, code);
Remove(clicknode);
AddNodeSorted(&DevList, clicknode, 0);
refreshdevlists();
if (IsListEmpty(&SelDevList)) EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], FALSE);
break;
case GD_PatternGad:
strncpy(pat, gadgetbuff(FindFileGadgets[GD_PatternGad - GD_DeviceLV]), PATTERNLEN);
if (strlen(pat) == 0)
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], FALSE);
else if ((*parse_func[match_case]) ((UBYTE *) pat, (UBYTE *) parsepat, 162) < 0)
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], FALSE);
else if (NOT(IsListEmpty(&SelDevList)))
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], TRUE);
break;
case GD_StartStopGad:
if (NOT(IsListEmpty(&SelDevList)))
{
if (NOT(IsListEmpty(&FoundList)) && Question(FindFileWnd, "File list not empty!\n"
"Do you want to save it?", NO))
SaveFoundFiles();
InitListView(FindFileWnd,FindFileGadgets[GD_FoundLV - GD_DeviceLV], NULL,0);
FreeRemember(FILEKEY, TRUE);
NewList(&FoundList);
InitListView(FindFileWnd,FindFileGadgets[GD_FoundLV - GD_DeviceLV], &FoundList,UNSETLVPOS);
for (i = GD_DeviceLV; i <= GD_DirFileCYGad; i++)
if ((i != GD_StartStopGad) && (i != GD_FoundLV))
EnableGadget(FindFileWnd,FindFileGadgets[i - GD_DeviceLV], FALSE);
breakit = FALSE;
for (node = SelDevList.lh_Head; node->ln_Succ; node = node->ln_Succ)
SearchFile(&(node->ln_Name)[1]);
for (i = GD_DeviceLV; i <= GD_DirFileCYGad; i++)
if ((i != GD_StartStopGad) && (i != GD_FoundLV))
EnableGadget(FindFileWnd,FindFileGadgets[i - GD_DeviceLV], TRUE);
}
break;
case GD_SaveFoundListGad:
if (NOT(IsListEmpty(&FoundList))) SaveFoundFiles();
break;
case GD_AllGad:
if (IsListEmpty(&DevList)) break;
node = DevList.lh_Head;
while (node->ln_Succ)
{
remnode = node->ln_Succ;
Remove(node);
AddTail(&SelDevList, node);
node = remnode;
}
InitListView(FindFileWnd,FindFileGadgets[GD_DeviceLV - GD_DeviceLV], NULL,0);
NewList(&DevList);
refreshdevlists();
if (strlen(pat)) EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], TRUE);
break;
case GD_NoneGad:
if (IsListEmpty(&SelDevList)) break;
node = SelDevList.lh_Head;
while (node->ln_Succ)
{
remnode = node->ln_Succ;
Remove(node);
AddNodeSorted(&DevList, node, 0);
node = remnode;
}
InitListView(FindFileWnd,FindFileGadgets[GD_SelDevLV - GD_DeviceLV], NULL,0);
NewList(&SelDevList);
refreshdevlists();
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], FALSE);
break;
case GD_CaseCYGad:
match_case = ((match_case == CASE) ? NO_CASE : CASE);
if (strlen(pat) == 0)
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], FALSE);
else if ((*parse_func[match_case]) ((UBYTE *) pat, (UBYTE *) parsepat, 162) < 0)
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], FALSE);
else
EnableGadget(FindFileWnd,FindFileGadgets[GD_StartStopGad - GD_DeviceLV], TRUE);
break;
case GD_DirFileCYGad:
match_type = code;
break;
}
return;
}
void
HandleFindFileKeys(ULONG code)
{
if (code == ESC)
{
if (NOT(IsListEmpty(&FoundList)) && Question(FindFileWnd, "File list not empty!\n"
"Do you want to save it?", NO))
SaveFoundFiles();
Flags.quit_ff = 1;
}
return;
}
/*
* FindFile() präsentiert eine Benutzeroberfläche, mit der die
* Suchkriterien eingestellt und das Handling gemanagt wird
*/
void
FindFile(void)
{
register struct IntuiMessage *message;
ULONG class,
code;
APTR object;
static int refr = TRUE;
DPOS;
HandleHelp(MN_FindFile);
NewList(&DevList);
NewList(&SelDevList);
NewList(&FoundList);
Flags.quit_ff = 0;
if (OpenASysWindow(OpenFindFileWindow,NO_KILL))
{
LockMainWindow(LOCK);
MakeDevList();
InitListView(FindFileWnd,FindFileGadgets[GD_DeviceLV - GD_DeviceLV], &DevList,UNSETLVPOS);
do
{
Wait(1L << FindFileWnd->UserPort->mp_SigBit);
while ((message = (struct IntuiMessage *) GT_GetIMsg(FindFileWnd->UserPort)) != NULL)
{
object = message->IAddress;
class = message->Class;
code = message->Code;
GT_ReplyIMsg(message);
switch (class)
{
case IDCMP_GADGETUP:
HandleFindFileGadgets(object, code);
break;
case IDCMP_VANILLAKEY:
HandleFindFileKeys(code);
break;
case IDCMP_CHANGEWINDOW:
case IDCMP_REFRESHWINDOW:
if (NOT(FindFileWnd->Flags & WFLG_ZOOMED))
{
/*
* Das Fenster soll nur EINMAL refreshed werden.
* Diese IDCMP-Message kommt aber auch dann, wenn ein
* Fenster verschoben wurde, weshalb ein Flag extra
* eingeführt wurde.
*/
if (NOT(refr))
{
RefreshRastPort(FindFileWnd,FindFileGadgets,gl, 4, TRUE, NULL);
refr = TRUE;
}
}
else
refr = FALSE;
MakeWindowRefresh(FindFileWnd);
break;
case IDCMP_CLOSEWINDOW:
if (NOT(IsListEmpty(&FoundList)) && Question(FindFileWnd, "File list not empty!\n"
"Do you want to save it?", NO))
SaveFoundFiles();
Flags.quit_ff = 1;
break;
}
}
}
while (NOT(Flags.quit_ff));
FreeRemember(FILEKEY, TRUE);
FreeRemember(DEVKEY, TRUE);
CloseASysWindow(&FindFileWnd, &FindFileGList, NULL);
LockMainWindow(UNLOCK);
}
return;
}